package number;

import string.UtilString;

/**
 * Description:
 * Created by E440 on 2017/5/19.
 */
public class UtilNumber {
    static public Float parseFloat(String s){
        if (UtilString.isNullOrEmpty(s)) {
            return null;
        }

        s=s.trim();
        s=s.replaceAll(",","");
        Float f=null;
        if (UtilString.right(s,1).compareToIgnoreCase("%")==0) {
            s=s.substring(0,s.length()-1);
            f=Float.parseFloat(s)/100;
        }else {
            f=Float.parseFloat(s);
        }
        return f;
    }

    static public Double parseDouble(String s){
        if (UtilString.isNullOrEmpty(s)) {
            return null;
        }
        s=s.trim();
        s=s.replaceAll(",","");
        Double d=null;
        if (UtilString.right(s,1).compareToIgnoreCase("%")==0) {
            s=s.substring(0,s.length()-1);
            d=Double.parseDouble(s)/100;
        }else {
            d=Double.parseDouble(s);
        }

        return d;
    }
}
